<?php

namespace Database\Seeders;

use App\Models\System\Menu;
use App\Models\System\Role;
use Illuminate\Database\Seeder;

class RoleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        if (Role::count() != 0) {
            return;
        }
        /** @var Role $role */
        $role = Role::create([
            'title' => '测试角色',
            'code' => 'test',
            'sort' => 0,
            'status' => 'normal',
        ]);

        // 全部权限给这个角色
        $role->menus()->attach(Menu::query()->pluck('id'));

        $role2 = Role::create([
            'title' => '测试修改',
            'code' => 'testedit',
            'sort' => 0,
            'status' => 'normal',
        ]);

        $role2->menus()->attach(Menu::query()->limit(5)->pluck('id'));
    }
}
